<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title></title>
	<script type="text/javascript">
		var filterParam = {};
		var datatable_content;
		var lpnNo;
		 $(function() {
			 initTable();
	       });
		function initTable(){
			$.ajax({
				   type : 'post',
					url : '${ctx}/v2/customerAreaGroup/queryCustomerWarehouseList',
					data : {
						customerCode:"${customerCode}"
					},
					dataType : 'json',
					success : function(data) {
						var status=data.status;
						var content = data.content;
						console.debug(content);
						if( status=='success'){
							var str="";
							$.each(content,function(i){
								var status=content[i].cainiaoAddressStatus=="0" ?"是":"否";
								str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td>"
								+"<td>"+content[i].areaGroupName+"</td>"
								+"<td>"+status+"</td>"
								+"<td><a data-target='#cainiaoAddressDetail' class='btn btn-small btn-default' data-toggle='modal'  onclick='update("+content[i].id+");'>修改</a></td></tr>";
							})
							$("#contentTableBody").html(str);
						}else{
							alert(content);
						}
					},
					error : function() {
						jAlert("网络繁忙，请稍后重试...删除","温馨提示");
					}
				}); 
		}
		function update(id){
			 $.ajax({
				   type : 'post',
					url : '${ctx}/v2/customerAreaGroup/updateCustomerAreaGroup',
					data : {
						id:id,
					},
					dataType : 'json',
					success : function(data) {
						var status=data.status;
						var content = data.content;
						if( status=='success'){
							$("#warehouseCodeDiv").html("<select  name=\"warehouseCode\"  id=\"warehouseCode\" class=\"form-control required\" >"
									+"<option value='"+content.areaGroupCode+"'>"+content.areaGroupName+"</option>"
									+"</select>");
							$("#useWarehouseAddressDiv").html("<select  name=\"useWarehouseAddress\"  id='useWarehouseAddress' value='"+content.cainiaoAddressStatus+"' class=\"form-control required\">"
									+"<option value=\"0\">是</option>"
									+"<option value=\"1\">否</option>"
									+"</select>");
						}else{
							alert(content);
						}
						$("#code").val(id);
					},
					error : function() {
						jAlert("网络繁忙，请稍后重试...删除","温馨提示");
					}
				});		  
			
		  }
	  //保存
	  function comfirm(){
		  var warehouseCode=$("#warehouseCode").val();
		  var useWarehouseAddress=$("#useWarehouseAddress").val();
		  var id=$("#code").val();
		  if(warehouseCode==null){
			  alert("请选择仓库!");
			  return;
		  }
		  $.ajax({
			   type : 'post',
				url : '${ctx}/v2/customerAreaGroup/updateCustomerWarehouseCainiaoAddress',
				data : {
					id:id,
					useWarehouseAddress:useWarehouseAddress
				},
				dataType : 'json',
				success : function(data) {
					var status=data.status;
					var content = data.content;
					if( status=='success'){
						alert(content);
					}else{
						alert(content);
					}
					  initTable();
				},
				error : function() {
					jAlert("网络繁忙，请稍后重试...删除","温馨提示");
					 initTable();
				}
			});		  
		
	  }
	
</script>
</head>

<body>
<section class="content">
 	<c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>
	
	<!-- <div class="row">
		<div class="col-md-12">

			Primary box
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">新增栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	
	</div>
	</div>
	</div>
	</div> -->
	
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 60px;">序号</th>
		    <th style="width: 60px;">仓库</th>
		    <th style="width: 60px;">菜鸟面单是否使用仓库地址</th>
			<th style="width: 180px;">操作</th>
		</tr></thead>
		<tbody id="contentTableBody">
		</tbody>
	</table>
	</div>
	</div></div>
	</div>
	
	<div id="cainiaoAddressDetail"  class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
		<div class="modal-content">
			<div class="modal-header">
				<h4 id="consignorTitle">修改</h4>
			</div>
			<div id="consignorDetailBodyOut" class="modal-body">
			<input type="hidden" id="code"/>
		<form class="form-search" id="queryForm"  >
		<fieldset>
			<div class="form-group row">
					<label  class="col-sm-3 control-label">
						仓库名称:
					</label>
					<div class="col-sm-6" id="warehouseCodeDiv">
						<!-- <select  name="warehouseCode"  id="warehouseCode"   class="form-control required" >
						   
						</select> -->
					</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-3 control-label">
							菜鸟面单是否使用仓库地址:
						</label>
						<div class="col-sm-6" id="useWarehouseAddressDiv">
							<!-- <select  name="useWarehouseAddress"  id="useWarehouseAddress" value="0"  class="form-control required" >
								<option value="0" >是</option>
								<option value="1" >否</option>
							</select> -->
						</div>
					</div>
					<div class="modal-footer bg-gray">
						<input id="submit_btn" class="btn btn-primary" type="button" onclick="comfirm();"
							value="保存" />
						&nbsp;
					</div>
				</fieldset>
		</form>
			</div>
			
		</div>	
		</div>	
		</div>

    
</section>	
</body>
</html>
